package com.cyh.exp.service.Impl;

import com.cyh.exp.mode.DownFile;
import com.cyh.exp.mode.Result;
import com.cyh.exp.mode.ReturnCode;
import com.cyh.exp.service.DownloadService;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@Service
public class DownloadServiceImpl implements DownloadService {


    @Override
    public Result<List> getFileall() {

        File scFileDir = new File("E://misuce_eg");  //下载目录

        File[] TexFile = scFileDir.listFiles(); //获取所有文件

        List<DownFile> files = new ArrayList<>();

        for (File value:TexFile){
            DownFile downFile = new DownFile();
            downFile.setFileName(value.getName());
            files.add(downFile);
        }

        if (files.isEmpty()){
            return new Result(
                    ReturnCode.SUCCESS.getCode(), ReturnCode.SUCCESS.getType(),
                    "查询成功",null
            );
        }
        else {

            return new Result<List>(
                    ReturnCode.SUCCESS.getCode(), ReturnCode.SUCCESS.getType(),
                    "查询成功",files
            );
        }

    }
}
